﻿
namespace Tentacle.Core
{
    using System;
    using static Tentacle.Utils.Hepler;

    public class WebPage
    {
        private readonly string  _html;
        private readonly string  _hash;
        private readonly WebSite _site;

        public WebPage(string content,WebSite site)
        {
            _html = content;
            _hash = Md5(content);
            _site = site ?? throw new NullReferenceException();
        }

        #region Property

        public string Html {
            get {
                return _html;
            }
        }

        public string Hash {
            get {
                return _hash;
            }
        }

        public WebSite Site {
            get {
                return _site;
            }
        }

        #endregion

        #region Override

        public override bool Equals(object obj)
        {
            if(obj is WebPage page) {
                return page._hash == this._hash;
            }
            return false;
        }

        public override int GetHashCode()
        {
            return _hash.GetHashCode() ^ _html.GetHashCode();
        }

        public override string ToString()
        {
            return _hash;
        }

        #endregion
    }
}
